"guess 数"  # 优化创建函数，用while函数代替循环，引入random函数，加入统计循环次数
import random
import sys

CX = input("是否开始游戏（是/否）：")
# 标记随机数，用于固定
# random.seed(1)
answer = random.randint(0, 10)
if CX == "是":
    temp = input("猜数（0——10）：")
    guess = int(temp)
    if guess == answer:
        print("yes")
        sys.exit(0)
    elif guess > answer:
        print("大了")
    elif guess < answer:
        print("小了")
    count = 1
    QX = input("是否继续（YES/NO）:")
    while QX == "YES":
        temp = input("猜数（0——10）：")
        guess = int(temp)
        if guess == answer:
            print("yes")
            print("猜错次数：", count)
            sys.exit(0)
        elif guess > answer:
            print("大了")
        elif guess < answer:
            print("小了")
        else:
            print("错误")
        count = count + 1
        QX = input("是否继续（YES/NO）:")
    while QX == "NO":
        print("结束")
        sys.exit(0)

elif CX == "否":
    print("结束")
else:
    print("无效")
